﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdministracijaDataLayer.Repository
{
    public class RGrupa : BaseRepository, InterfaceRepository<Grupa>
    {
        public IQueryable<Grupa> VratiSve()
        {
            //dc.ExecuteQuery<Grupa>("select * from Gryop where id = {0} nad id122 = {1}", 1,2);
           

            dc = new AdministracijaDataContext();
            return dc.Grupas;
        }

        public Grupa Nov()
        {
            jeNov = true;

            Grupa n = new Grupa();
            n.Naziv = "unesite naziv";
            return n;
        }

        public Grupa Izmeni(int id)
        {
            jeNov = false;

            Grupa g = (from t in dc.Grupas
                      where t.GrupaId == id
                      select t).SingleOrDefault();

            g = dc.Grupas.SingleOrDefault(c => c.GrupaId == id);

            return g;
        }

        public int Snimi(Grupa t)
        {
            if (jeNov)
                dc.Grupas.InsertOnSubmit(t);
            dc.SubmitChanges();
            return t.GrupaId;

        }

        public void Brisi(int id)
        {
            Grupa g = dc.Grupas.SingleOrDefault(c => c.GrupaId == id);
            dc.Grupas.DeleteOnSubmit(g);
            dc.SubmitChanges();
        }
    }
}
